package com.cdtye.itps.cms.dao.enums;

import com.cdtye.common.webcore.util.MapUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 铁路类型枚举
 * @author gaozx
 */
@Getter
@AllArgsConstructor
public enum RailTypeEnum {

    /**
     * 高铁
     */
    GT(1, "高铁", "GT"),
    /**
     * 普铁
     */
    PT(2, "普铁", "PT");

    /**
     * 类型
     */
    public final int type;
    /**
     * 名称
     */
    public final String text;
    /**
     * 值
     */
    public final String value;

    public static String getTextByType(int type) {
        for (RailTypeEnum model : RailTypeEnum.values()) {
            if (model.getType() == type) {
                return model.getText();
            }
        }
        return "";
    }

    public static String getValueByType(int type) {
        for (RailTypeEnum model : RailTypeEnum.values()) {
            if (model.getType() == type) {
                return model.getValue();
            }
        }
        return "";
    }

    public static String getTextByValue(String value) {
        if (StringUtils.isEmpty(value)) {
            return "";
        }
        for (RailTypeEnum model : RailTypeEnum.values()) {
            if (model.getValue().equals(value)) {
                return model.getText();
            }
        }
        return "";
    }
    public static List<Map<String, Object>> list() {
        List<Map<String, Object>> list = new ArrayList();
        for (RailTypeEnum model : RailTypeEnum.values()) {
            list.add(MapUtil.build().put("code", model.getValue()).put("text", model.getText()).over());
        }
        return list;
    }
}
